package com.dao;

import java.util.List;

import com.model.User;
import com.util.JdbcUtil;

public class UserDao {
	JdbcUtil jdbc=new JdbcUtil();
	//用户登录，通过返回集合是否为空判断登录与否
	public List<User> login(String uname,String upassword){
		List<User> users = null;
		String sql ="select * from user where uname=? and upassword=?";
		users = jdbc.queryPreparedStatement(sql, User.class,uname,upassword);
		jdbc.close();
		return users;
	}
	//用户注册，
	public void regist(User user) throws Exception{
		String sql ="insert into user values(null,?,?,?,?)";
		jdbc.updatePreparedStatement(sql, user.getUname(),
				user.getUpassword(),user.getUphone(),user.getUaddress());
		jdbc.close();
	}
	//通过用户名查询数据
	public List<User>  queryUserByUname(String uname) {
		List<User> users = null;
		String sql ="select * from user where uname=?";
		users = jdbc.queryPreparedStatement(sql, User.class,uname);
		jdbc.close();
		return users;
	}
	//用户修改个人信息
	public void updateMess(User user) throws Exception{
		String sql ="update user set uname=?,upassword=?,uphone=?,uaddress=? where uid=?";
		jdbc.updatePreparedStatement(sql, user.getUname(),
				user.getUpassword(),user.getUphone(),user.getUaddress(),user.getUid());
		jdbc.close();
	}
}
